package com.evan.review;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.evan.review.anr.ANRMainActivity;
import com.evan.review.architecture.ArchitectureMainActivity;
import com.evan.review.basic.BasicJavaActivity;
import com.evan.review.classloader.ClassLoaderActivity;
import com.evan.review.eventdispatch.EventDispatchMainActivity;
import com.evan.review.fragment.FragmentActivity;
import com.evan.review.handler.HandlerMainActivity;
import com.evan.review.ipc.IPCMainActivity;
import com.evan.review.launchmode.LaunchModeActivity;
import com.evan.review.lifecycle.LifecycleActivity;
import com.evan.review.stickytop.StickyTopActivity;
import com.evan.review.thread.ThreadMainActivity;
import com.evan.review.viewpager.ViewPagerMainActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        initViews();
    }

    private void initViews() {
        // 初始化各个知识点的按钮
        Button btnLaunchMode = findViewById(R.id.btn_launch_mode);
        Button btnLifecycle = findViewById(R.id.btn_activity_lifecycle);
        Button btnFragment = findViewById(R.id.btn_fragment);
        Button btnViewPager = findViewById(R.id.btn_viewpager);
        Button btnANR = findViewById(R.id.btn_anr);
        Button btnHandler = findViewById(R.id.btn_handler);
        Button btnClassLoader = findViewById(R.id.btn_classloader);
        Button btnThread = findViewById(R.id.btn_thread);
        Button btnIPC = findViewById(R.id.btn_ipc);
        Button btnArchitecture = findViewById(R.id.btn_architecture);
        Button btnArrayBasic = findViewById(R.id.btn_array_basic);
        Button btnEventDispatch = findViewById(R.id.btn_event_dispatch);
        Button btnStickyTop = findViewById(R.id.btn_sticky_top);

        btnLaunchMode.setOnClickListener(this);
        btnLifecycle.setOnClickListener(this);
        btnFragment.setOnClickListener(this);
        btnViewPager.setOnClickListener(this);
        btnANR.setOnClickListener(this);
        btnHandler.setOnClickListener(this);
        btnClassLoader.setOnClickListener(this);
        btnThread.setOnClickListener(this);
        btnIPC.setOnClickListener(this);
        btnArchitecture.setOnClickListener(this);
        btnArrayBasic.setOnClickListener(this);
        btnEventDispatch.setOnClickListener(this);
        btnStickyTop.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();

        if (id == R.id.btn_launch_mode) {
            // 跳转到启动模式学习
            startActivity(new Intent(this, LaunchModeActivity.class));
        } else if (id == R.id.btn_activity_lifecycle) {
            // 跳转到生命周期学习
            startActivity(new Intent(this, LifecycleActivity.class));
        } else if (id == R.id.btn_fragment) {
            // 跳转到Fragment生命周期学习
            startActivity(new Intent(this, FragmentActivity.class));
        } else if (id == R.id.btn_viewpager) {
            // 跳转到ViewPager学习
            startActivity(new Intent(this, ViewPagerMainActivity.class));
        } else if (id == R.id.btn_anr) {
            // 跳转到ANR示例学习
            startActivity(new Intent(this, ANRMainActivity.class));
        } else if (id == R.id.btn_handler) {
            // 跳转到Handler机制学习
            startActivity(new Intent(this, HandlerMainActivity.class));
        } else if (id == R.id.btn_classloader) {
            // 跳转到ClassLoader类加载机制学习
            startActivity(new Intent(this, ClassLoaderActivity.class));
        } else if (id == R.id.btn_thread) {
            // 跳转到线程与线程池学习
            startActivity(new Intent(this, ThreadMainActivity.class));
        } else if (id == R.id.btn_ipc) {
            // 跳转到IPC进程间通信学习
            startActivity(new Intent(this, IPCMainActivity.class));
        } else if (id == R.id.btn_architecture) {
            // 跳转到架构设计模式学习
            startActivity(new Intent(this, ArchitectureMainActivity.class));
        } else if (id == R.id.btn_array_basic) {
            // 跳转到Java基础学习
            startActivity(new Intent(this, BasicJavaActivity.class));
        } else if (id == R.id.btn_event_dispatch) {
            // 跳转到事件分发机制学习
            startActivity(new Intent(this, EventDispatchMainActivity.class));
        } else if (id == R.id.btn_sticky_top) {
            // 跳转到吸顶效果学习
            startActivity(new Intent(this, StickyTopActivity.class));
        }
        // 其他知识点按钮待添加...
    }
}